package com.geeka.d12;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class HelloInetAddr {
    public static void main(String[] args) {

        try {
            InetAddress localHost = null;
            localHost = InetAddress.getLocalHost();
            System.out.println(InetAddress.getLocalHost().getHostName());
            System.out.println(InetAddress.getLocalHost().getHostAddress());
            System.out.println(localHost);

            InetAddress bdAddr = InetAddress.getByName("www.baidu.com");
            System.out.println(bdAddr.getHostName());
            System.out.println(bdAddr.getHostAddress());

            //ping 功能
             byte[] ipBytes ={10,10,10, 12};
            InetAddress byAddress = InetAddress.getByAddress(ipBytes);
            try {
                boolean isReachable = byAddress.isReachable(3000);
                System.out.println("ping 10.10.10.12是否畅通: " + isReachable);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }
}
